var vue = new Vue({
	el: "body",
	data: {
		username: "",
		isloading: true,
		post: [],
		type: []
	},
	created: function() {
		var token = sessionStorage.getItem("token");
		var appid = sessionStorage.getItem("appid");
		this.username = sessionStorage.getItem("username");
		if(this.username == null) {
			var url = "http://v2.mashupcloud.cn/SQL/getAllPost/";
			var name = "getAllPost";
			this.getAllPost(appid, token, url, name);
		} else {
			var url = "http://v2.mashupcloud.cn/SQL/get_post/";
			var name = "get_post";
			this.getType(appid, token);
			//this.getpost(appid,token,url,name);
		}
	},
	methods: {
		getAllPost: function(appid, token, url1, name1) {
			$.ajax({
				type: 'get',
				url: url1,
				data: {
					appid: appid,
					token: token,
					name: name1
				},
				success: function(json) {
					console.log("json==" + json);
					vue.post = JSON.parse(json)[2];
					console.log(vue.post);
					vue.isloading = false
				},
				error: function(json) {
					console.log("err:" + json);
				}
			});
		},
		getType: function(appid, token) {
			$.ajax({
				type: 'get',
				url: "http://v2.mashupcloud.cn/SQL/select_userinfo/",
				async: true,
				data: {
					appid: appid,
					token: token,
					name: 'select_userinfo',
					_v1: this.username
				},
				success: function(json) {
					vue.type = JSON.parse(json)[2][0].type;
					vue.type = vue.type.split(",");
					console.log(vue.type);
					for(var i = 0; i < vue.type.length; i++) {
						vue.getpost(appid, token, vue.type[i]);
					}
				},
				error: function(json) {
					console.log("err:" + json);
				}
			});
		},
		getpost: function(appid, token, type) {
			$.ajax({
				type: 'get',
				url: 'http://v2.mashupcloud.cn/SQL/get_post/',
				data: {
					appid: appid,
					token: token,
					name: 'get_post',
					_v1: type
				},
				success: function(json) {
					console.log("json==" + json);
					var arr = JSON.parse(json)[2];
					console.log(arr.length);
					for(var i = 0; i < arr.length; i++) {
						vue.post.push(arr[i]);
					}
					console.log(vue.post);
					vue.isloading = false
				},
				error: function(json) {
					console.log("err:" + json);
				}
			});
		},
		Detail:function(index){
			sessionStorage.setItem("postID",this.post[index].ID);
			location.href="../details/details.html"
		}
	}
});